package demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86185
 * Date: 2023-04-02
 * Time: 10:26
 */

class Alg<T extends Comparable<T>> {//擦除为一个实现了这个接口的类型//泛型上界
    public T findMax(T[] array) {
        T max = array[0];
        for (int i = 1; i < array.length; i++) {
            //引用类型不能用<>=比较
            if(max.compareTo(array[i]) < 0) {
                max = array[i];
            }
        }
        return max;
    }
}
class Alg2 {
    public static<T extends Comparable<T>> T findMax(T[] array) {
        T max = array[0];
        for (int i = 1; i < array.length; i++) {
            //引用类型不能用<>=比较
            if(max.compareTo(array[i]) < 0) {
                max = array[i];
            }
        }
        return max;
    }
}
public class Test2 {
    public static void main2(String[] args) {
        Integer[] array = {1,5,2,7,19,4};
        Integer max = Alg2.findMax(array);
        System.out.println(max);
    }
    public static void main(String[] args) {
        Alg<Integer> alg = new Alg<>();
        Integer[] array = {1,5,2,7,19,4};
        Integer max = alg.findMax(array);
        System.out.println(max);
    }
}
